//
//  YWAssetsEquipmentListTableViewCell.m
//  maintain
//
//  Created by 烟雨云渊 on 16/10/26.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWAssetsEquipmentListTableViewCell.h"
#import "YWMacro.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"

#import "YWAssetCheckRecordDetails.h"
#import "YWEquipmentType.h"
#import "YYLabel.h"
#import "YWCommonTool.h"

@interface YWAssetsEquipmentListTableViewCell()
/*设备*/
@property (nonatomic,strong) YYLabel * equipmentLabel;
/*是否正常*/
@property (nonatomic,strong) YYLabel * statusLabel;
/*应有数量*/
@property (nonatomic,strong) YYLabel * dueNumberLabel;
/*实际数量*/
@property (nonatomic,strong) YYLabel * realLabel;
@end

@implementation YWAssetsEquipmentListTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setEquipmentList:(YWAssetCheckRecordDetails *)equipmentList{
    _equipmentList = equipmentList;

    NSString*equipmentTypeName = _equipmentList.equipmentType.equipmentTypeName?:@"无";
    _equipmentLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"设备: " firstColor:[UIColor customTextGrayColor] secondText:equipmentTypeName secondColor:[UIColor blackColor] font:kContentFont];
    _statusLabel.text = _equipmentList.result == YWCheckRecordResultNormal?@"正常":@"异常";
    _statusLabel.textColor = _equipmentList.result == YWCheckRecordResultNormal?[UIColor customTextGrayColor]:[UIColor customRedColor];
    
    NSString *referQuantity =[NSString stringWithFormat:@"%ld",(long)_equipmentList.referQuantity];
    _dueNumberLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"应有数量: " firstColor:[UIColor customTextGrayColor] secondText:referQuantity secondColor:[UIColor blackColor] font:kContentFont];
    NSString*checkQuantity = [NSString stringWithFormat:@"%ld",(long)_equipmentList.checkQuantity];
    _realLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"实际数量: " firstColor:[UIColor customTextGrayColor] secondText:checkQuantity secondColor:[UIColor blackColor] font:kContentFont];
}

- (void)setUpSubviews{
    [self.equipmentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.statusLabel.mas_right);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(6);
        make.right.mas_equalTo(self.contentView).offset(-8);
    }];
    [self.dueNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.equipmentLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.realLabel.mas_right);
        make.bottom.mas_equalTo(self.contentView).offset(-8);
    }];
    [self.realLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.dueNumberLabel.mas_centerY);
        make.right.mas_equalTo(self.contentView).offset(-8);
        make.bottom.mas_equalTo(self.contentView).offset(-8);
    }];
}

- (YYLabel *)equipmentLabel{
    if (!_equipmentLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _equipmentLabel = label;
        [self.contentView addSubview:_equipmentLabel];
    }
    return _equipmentLabel;
}

- (YYLabel *)statusLabel{
    if (!_statusLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = kContentFont;
        _statusLabel = label;
        [self.contentView addSubview:_statusLabel];
    }
    return _statusLabel;
}

- (YYLabel *)dueNumberLabel{
    if (!_dueNumberLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _dueNumberLabel = label;
        [self.contentView addSubview:_dueNumberLabel];
    }
    return _dueNumberLabel;
}

- (YYLabel *)realLabel{
    if (!_realLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _realLabel = label;
        [self.contentView addSubview:_realLabel];
    }
    return _realLabel;
}



@end
